<?php

/**
 * 录音Model
 *注册文件名和类名一致，包括大小写以及UTF8编码
 * AppParentsModel description.
 *
 * @version 1.0
 * @author Administrator
 */
Namespace Api\Model;
use Think\Model;
class AppRecordModel extends Model
{
    /**
     * 获取录音的基地址,由于录音保存地址以反协杠开头
     * ，所以此地址尾部无反杠
     * @return mixed
     */
    public function getBaseUrl(){
        return C("PUBLIC_UPLOAD_URL");
    }
    public function getDb(){
        return  MwithNoPrefix("app_record");
    } 
    /**
     * 用户自己取录音列表
     * @param mixed $strUsername 
     * @return mixed
     */
    public function getRecordList($strUsername){
      $db =  $this->getDb();
      $arrResult =  $db->where("username='%s'",$strUsername)->order("id desc")->select();
      // die($db->getLastSql());
      return $arrResult;
    }
    public function updateCountCache($strUsername){
        $strSql="update tb_students set apprecordcount = (select count(*) from APP_Record where username='%s') where username='%s'";
        $db = $this->getDb();
        $db->execute($strSql,$strUsername,$strUsername);
    }
    public function delRecord($strUsername,$iID)
    {
        $db =  $this->getDb();
        $db->where("id=%d and username='%s'",$iID,$strUsername)->delete();
        $this->updateCountCache($strUsername);
    }
    
    public function getRecordUrl($strRecordFilePath)
    {
        if($strRecordFilePath==null)
        {
            return "";
        }
        return C("PUBLIC_UPLOAD_URL").$strRecordFilePath;
    }
    /**
     * 获取磨耳朵的录音标识
     * @return mixed
     */
    public function getMoerduoRecordType(){
       return "moerduorecord";
    }
    
    /**
     * 获取磨耳朵的录音标识
     * @return mixed
     */
    public function getClassworkType(){
        return "classworkrecord";
    }
    
    /**
     * 每次录音所增加的花蜜
     * @return mixed
     */
    public function getNectarNumWhenRecord(){
        return 10;
    }
}
